package it.afs.worklog.application;

import it.afs.utils.PropertyManager;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.Page;
import org.apache.wicket.Request;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.Response;
import org.apache.wicket.Session;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebRequest;

public class WorkLog extends WebApplication
{
	private static final Log log = LogFactory.getLog(WorkLog.class);
	
	@Override
	public Class<? extends Page> getHomePage()
	{
		return HomePage.class;
	}
	
	@Override
	protected void init()
	{
		super.init();
		try {
			PropertyManager.init(getServletContext().getResourceAsStream("WEB-INF/properties/worklog.properties"));
			log.debug("Properties worklog.properties loaded");
		} catch (Exception e) {
			log.error("Unable to load worklog.properties", e);
		}
		
		getApplicationSettings().setPageExpiredErrorPage(LoginPage.class);
	}
	
	@Override
	public RequestCycle newRequestCycle(Request request, Response response)
	{
		return new HibernateWebRequestCycle(this, (WebRequest) request, response);
	}
	
	@Override
	public Session newSession(Request request, Response response)
	{
		return new WorkLogSession(request);
	}
}